package com.jinyang.login

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.jinyang.baserouter.*
import com.jinyang.baserouter.model.TestObj
import com.jinyang.baserouter.model.TestParcelable
import com.jinyang.baserouter.model.TestSerializable
import com.jinyang.login.databinding.ActivityLoginBinding

@Route(path = PATH_ACTIVITY_LOGIN)
class LoginActivity : AppCompatActivity() {
    @Autowired
    @JvmField
    var key1: Int? = -1

    @JvmField
    @Autowired(name = "key2", required = true, desc = "userName field")
     var name: String?=null

    private var key3: String? = ""

    @Autowired
    @JvmField
    var testObj: TestObj? = null

    @Autowired
    @JvmField
    var list: List<TestObj?>? = null

    @Autowired
    @JvmField
    var testSerializable: TestSerializable? = null

    @Autowired
    @JvmField
    var testParcelable: TestParcelable? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        val binding =
            DataBindingUtil.setContentView<ActivityLoginBinding>(this, R.layout.activity_login)
        binding.btn2main.setOnClickListener {
            routerNavigation(PATH_ACTIVITY_MAIN)
        }
        binding.btnSetResult.setOnClickListener {
//            setResult(999)
            setResult(999, Intent().putExtra("key1", 111))
            finish()
        }
        log("key1=$key1")
        log("name=$name")
        log("key3=$key3")
        log("testObj=$testObj")
        log("list=$list")
        log("testSerializable=${GsonUtils.toJson(testSerializable)}")
        log("testParcelable=${GsonUtils.toJson(testParcelable)}")
        binding.btnToweb.setOnClickListener {
            routerNavigation(
                PATH_ACTIVITY_WEB,
                mapOf("url" to "file:///android_asset/scheme-test.html"),
                group = "web1"
            )
        }
    }

}